import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { BrowserRouter, Switch, Redirect, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { NightStars, NightStarsInitalState } from './allLogics/reducers';
import LoginContainer from './container/Login';
import HomeContainer from './container/Home';
import MyContainer from './container/Myinfo';
import FooterContainer from './container/Footer';
import { setStore } from './allLogics/stores';

const store = createStore(NightStars, NightStarsInitalState, applyMiddleware(thunk));
setStore(store); // store的初始

ReactDOM.render(
    <Provider store={store}>
        <BrowserRouter>
            <Switch>
                <Route path="/login" component={LoginContainer} />
                <Route
                    path="/home"
                    render={() => (
                        <div>
                            <FooterContainer />
                            <Route path="/home/homeMall" component={HomeContainer} />
                            <Route path="/home/myInfo" component={MyContainer} />
                        </div>
                    )}
                ></Route>
                <Redirect to="/login" />
            </Switch>
        </BrowserRouter>
    </Provider>,
    document.getElementById('root')
);
